package com.wnxy.sdd.config.mp;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MybatisPlusConfig {

    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        // 自定义分页拦截器，处理当前页大于总页数时候，设置当前页为总页数
        PageOverflowInterceptor paginationInnerInterceptor = new PageOverflowInterceptor(DbType.MYSQL);
        paginationInnerInterceptor.setOverflow(true);

        // 把分页拦截器添加mp拦截器中
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        interceptor.addInnerInterceptor(paginationInnerInterceptor);
        return interceptor;
    }
}